package com.example.asus.a17376037_zq_market;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import Info.Product;

public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHolder> {
    private Context mContext;
    private List<Product> mProductList;

    static  class ViewHolder extends RecyclerView.ViewHolder{
        ImageView photoId;
        TextView productname;

        public ViewHolder(View view) {
            super(view);
            photoId = view.findViewById(R.id.product_image);
            productname = view.findViewById(R.id.product_massage);
        }
    }
    public ProductAdapter(List<Product> productList){
        mProductList=productList;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(mContext==null){
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.product_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Product product = mProductList.get(position);
        holder.photoId.setImageResource(product.getPhotoId());
        holder.productname.setText(product.getProductname());
    }

    @Override
    public int getItemCount() {
        return mProductList.size();
    }

}
